#FROM harbor.sh.zts.com.cn/base/java:latest
FROM debian:jessie

MAINTAINER lijf <lijf@zts.com.cn>

USER root

#install openssh-server
RUN apt-get update && apt-get install -y wget  openssh-server  


#install jdk
# Install the python script required for "add-apt-repository"
#RUN apt-get update && apt-get install -y software-properties-common

#get jdk
RUN wget --header "Cookie: oraclelicense=accept-securebackup-cookie" \
         --no-verbose -O /tmp/jdk-8u66-linux-x64.tar.gz \
             http://download.oracle.com/otn-pub/java/jdk/8u66-b17/jdk-8u66-linux-x64.tar.gz

# install maven
RUN tar xzf /tmp/jdk-8u66-linux-x64.tar.gz -C /opt/
RUN update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_66/bin/java 100
RUN update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_66/bin/javac 100
RUN rm -f  /tmp/jdk-8u66-linux-x64.tar.gz
ENV JAVA_HOME /opt/jdk1.8.0_66


RUN apt-get update && apt-get install  -y apt-transport-https ca-certificates gnupg2
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
RUN echo "deb https://apt.dockerproject.org/repo debian-jessie main" >> /etc/apt/sources.list 
RUN apt-get update && apt-get install -y docker-engine

# install git
RUN apt-get install -y git

# get maven 3.3.9
RUN wget --no-verbose -O /tmp/apache-maven-3.3.9-bin.tar.gz http://mirrors.cnnic.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz

# install maven
RUN tar xzf /tmp/apache-maven-3.3.9-bin.tar.gz -C /opt/
RUN ln -s /opt/apache-maven-3.3.9 /opt/maven
RUN ln -s /opt/maven/bin/mvn /usr/local/bin
RUN rm -f  /tmp/apache-maven-3.3.9-bin.tar.gz
ENV MAVEN_HOME /opt/maven

#install dockerirze
ARG DOCKERIZE_VERSION=v0.3.0
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
    && tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
    && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
	

RUN mkdir /var/run/sshd

EXPOSE 22 

#change the password of root
ARG rootpasswd=123456
RUN echo "root:$rootpasswd"|chpasswd

# Add user jenkins to the image
RUN adduser --quiet jenkins

# Set password for the jenkins user (you may want to alter this).
RUN echo "jenkins:jenkins" | chpasswd

ENV HOME /home/jenkins

ADD conf/settings.xml $HOME/.m2/
ADD conf/harbor.sh.zts.com.cn.crt /usr/local/share/ca-certificates/harbor.sh.zts.com.cn.crt

RUN chown -R jenkins:jenkins $HOME

# private key
RUN mkdir $HOME/.ssh
RUN chown -R jenkins:jenkins $HOME/.ssh

#avoid to use sudo 
RUN addgroup -a jenkins docker

ADD bin/start.sh $HOME/bin/ 
RUN chmod +x $HOME/bin/*.sh

ENTRYPOINT $HOME/bin/start.sh 

